/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import com.openbravo.bean.ServiceCalendar;
import com.openbravo.bean.ServiceCalendarDayLine;
import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.StaticSentence;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;
import java.util.List;

/**
 *
 * @author Administrator
 */
public class ServiceCalendarDayLineDAO extends ModifiedLogDAO<ServiceCalendarDayLine>{

    public ServiceCalendarDayLineDAO(I_Session s) {
        super(s);
    }

    @Override
    public TableDefinition getTable() {
        return new TableDefinition(s,
                "SERVICECALENDARDAYLINE",
                new Field[]{
                          new Field("ID",Datas.STRING,Formats.STRING),
                          new Field("SERVICECALENDAR_ID",Datas.STRING,Formats.STRING,ServiceCalendar.class),
                          new Field("ABLE",Datas.BOOLEAN,Formats.BOOLEAN),
                          new Field("STARTDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("ENDDATE",Datas.TIMESTAMP, Formats.TIMESTAMP),
                          new Field("MEMO",Datas.STRING,Formats.STRING),
                          new Field("LASTMODIFIED",Datas.TIMESTAMP, Formats.TIMESTAMP)
                },
                new int[]{0});
    }

    @Override
    public void writeInsertValues(DataWrite dp, ServiceCalendarDayLine obj) throws BasicException {
         dp.setString(1,obj.getId());
         dp.setString(2, obj.getServiceCalenderId());
         dp.setBoolean(3,obj.isAble());
         dp.setTimestamp(4,obj.getStart());
         dp.setTimestamp(5,obj.getEnd());
         dp.setString(6,obj.getMemo());
         dp.setTimestamp(7,obj.getLastModified());
    }

    @Override
    public Class getSuportClass() {
        return ServiceCalendarDayLine.class;
    }

    public ServiceCalendarDayLine readValues(DataRead dr,ServiceCalendarDayLine obj) throws BasicException {
       if(obj==null)
    	   obj=new ServiceCalendarDayLine();
       obj.setId(dr.getString(1));
       obj.setServiceCalenderId(dr.getString(2));
       obj.setAble(dr.getBoolean(3));
       obj.setStart(dr.getTimestamp(4));
       obj.setEnd(dr.getTimestamp(5));
       obj.setMemo(dr.getString(6));
       obj.setLastModified(dr.getTimestamp(7));
       return obj;
    }

    public List<ServiceCalendarDayLine> listServiceCalendarDayLineByService(String serviceId) throws BasicException {
        return new StaticSentence(s,getTableDefinition().getListSQL("W")+",SERVICECALENDAR S,SERVICE C WHERE W.SERVICECALENDAR_ID=S.ID AND S.ID=C.SERVICECALENDAR_ID AND C.ID="+serviceId,null,this).list();
    }

}
